package com.hfi.security.core.social;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.view.AbstractView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ChangLiang
 * @date 2019/8/26
 */
public class HfiConnectView extends AbstractView {

    @Autowired
    private ObjectMapper objectMapper;

    @Override
    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("application/json;charset=utf-8");
        Map<String, String> map = new HashMap<>(1);

        if (model.get("connections")==null) {
            map.put("result", "解绑成功");
            response.getWriter().write(objectMapper.writeValueAsString(map));
            return;
        }
        map.put("result", "绑定成功");
        response.getWriter().write(objectMapper.writeValueAsString(map));
    }
}
